//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.wi.propertie;

import java.io.*;
import java.util.Properties;

public class PropertyCRUD {

    public PropertyCRUD() {
        serial = 0;
        ip = "";
        url = "";
        firstUrl = "";
        driver = "";
        user = "";
        pass = "";
        firstUser = "";
        firstPass = "";
        backupHome = "";
        dataBaseHome = "";
        init();
    }

    private void init() {
        Properties p = new Properties();
        try {
            FileInputStream fis = new FileInputStream("lib/wi.properties");
            p.load(fis);
            serial = Integer.parseInt(p.getProperty("serial"));
            ip = p.getProperty("ip");
            url = p.getProperty("url");
            firstUrl = p.getProperty("first_url");
            driver = p.getProperty("driver");
            pass = p.getProperty("pass");
            user = p.getProperty("user");
            firstPass = p.getProperty("first_pass");
            firstUser = p.getProperty("first_user");
            backupHome = p.getProperty("backup_home");
            dataBaseHome = p.getProperty("database_home");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }

    private void updateProperty() {
        Properties p = new Properties();
        p.setProperty("serial", Integer.toString(serial));
        p.setProperty("ip", ip);
        p.setProperty("url", url);
        p.setProperty("first_url", firstUrl);
        p.setProperty("driver", driver);
        p.setProperty("pass", pass);
        p.setProperty("user", user);
        p.setProperty("first_user", firstUser);
        p.setProperty("first_pass", firstPass);
        p.setProperty("backup_home", backupHome);
        p.setProperty("database_home", dataBaseHome);
        try {
            p.store(new FileOutputStream("lib/wi.properties"), "WI properties file db connection");
        } catch (IOException ioe) {
            System.out.println("error Saving properties file: " + ioe);
        }
    }

    public void update() {
        updateProperty();
    }

    public int getSerial() {
        return serial;
    }

    public String getIP() {
        return ip;
    }

    public String getUrl() {
        return url;
    }

    public String getFirstUrl() {
        return firstUrl;
    }

    public String getDriver() {
        return driver;
    }

    public String getUser() {
        return user;
    }

    public String getPass() {
        return pass;
    }

    public String getFirstUser() {
        return firstUser;
    }

    public String getFirstPass() {
        return firstPass;
    }

    public String getDataBaseHome() {
        return dataBaseHome;
    }

    public String getBackupHome() {
        return backupHome;
    }

    public void setBackupHome(String string) {
        backupHome = string;
    }

    public void setDataBaseHome(String string) {
        dataBaseHome = string;
    }

    public void setDriver(String string) {
        driver = string;
    }

    public void setFirstPass(String string) {
        firstPass = string;
    }

    public void setFirstUser(String string) {
        firstUser = string;
    }

    public void setIp(String string) {
        ip = string;
    }

    public void setPass(String string) {
        pass = string;
    }

    public void setSerial(int i) {
        serial = i;
    }

    public void setUrl(String string) {
        url = string;
    }

    public void setUser(String string) {
        user = string;
    }

    public void setFirstUrl(String string) {
        firstUrl = string;
    }
    private int serial;
    private String ip;
    private String url;
    private String firstUrl;
    private String driver;
    private String user;
    private String pass;
    private String firstUser;
    private String firstPass;
    private String backupHome;
    private String dataBaseHome;
}
